package com.zgw.his.design.model.property.edit;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wb.internal.core.model.property.Property;
import org.eclipse.wb.internal.core.model.property.editor.TextDialogPropertyEditor;

import com.zgw.his.common.ValueUtil;
import com.zgw.his.design.model.property.edit.dialog.InputSelectedDialog;
import com.zgw.his.design.resource.BaseResource;

/**
 * 输入可选项 编辑
 * */
public class InputSelectedPropertyEditor extends TextDialogPropertyEditor {

	// //////////////////////////////////////////////////////////////////////////
	//
	// Instance
	//
	// //////////////////////////////////////////////////////////////////////////
	public static final InputSelectedPropertyEditor INSTANCE = new InputSelectedPropertyEditor();
	public static final String TITLE = "可选项";

	private InputSelectedPropertyEditor() {

	}

	@Override
	protected void openDialog(Property property) throws Exception {
		String code = (String) property.getValue();
		InputSelectedDialog dlg = new InputSelectedDialog(Display.getDefault()
				.getActiveShell(), SWT.NONE, code);
		String newValue = dlg.open();
		if (!ValueUtil.equal(code, newValue)) {
			property.setValue(newValue);
		}

	}

	@Override
	protected String getText(Property property) throws Exception {
		String text = BaseResource.getInputSelectedName((String) property
				.getValue());
		return ValueUtil.hasValue(text) ? "[" + text + "]" : "";
	}

	public String getTitle() {
		return "可选项";
	}

}
